package com.gjintel.business.webtypemanage.dao.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.stereotype.Repository;

import com.gjintel.business.webcontent.model.WebContent;
import com.gjintel.business.webtypemanage.dao.IWebTypeManageDao;
import com.gjintel.business.webtypemanage.model.WebTypeInfo;
import com.gjintel.framework.dept.model.Dept;
import com.gjintel.sdk.base.dao.HibernateGenericDAO;
import com.gjintel.sdk.base.dao.Page;
import com.gjintel.sdk.base.dao.Sort;
import com.gjintel.sdk.util.StringUtil;


/**
 * @description 文章类型数据处理实现
 * @author Ant-K
 * @date 2016-3-16 下午19:38:39
 */

@Repository("webTypeManageDao")
public class WebTypeManageDaoImpl extends HibernateGenericDAO implements IWebTypeManageDao{

	@SuppressWarnings("unchecked")
	public List<WebTypeInfo> findAll() {
		String hql = "from WebTypeInfo g where g.flag=0 order by g.createTime asc";//order by g.disSort asc";
		return this.find(hql);
	}
	@SuppressWarnings("unchecked")
	public List<Dept> findDeptAll() {
		String hql = "from Dept d where d.type=2";
	    //String hql = "from WebContent g where g.flag=0 group by g.deptId";
		return this.find(hql);
	}
	@SuppressWarnings("unchecked")
	public void findAll(Page page, WebTypeInfo info, Sort sort) {
		StringBuffer hql = new StringBuffer("from WebTypeInfo g where g.flag=0 and g.id!='1'");
		List<String> params = new ArrayList<String>(2);
		if (info != null) {
			if (!StringUtil.isEmpty(info.getName())) {
				hql.append(" and g.name like ? ");
				params.add("%" + info.getName().trim() + "%");
			}
			if (!StringUtil.isEmpty(info.getPid())) {
				hql.append(" and g.pid=? ");
				params.add(info.getPid().trim());
			}
		}
		this.findAsPage(hql.toString(), page, sort, "g", true, params.toArray());
	}
	@SuppressWarnings("unchecked")
	public List<Dept> getDeptName(String deptId) {
		
		String hql = "from Dept g where g.id='"+deptId+"'";
		return this.find(hql);
	}
}
